package com.feicheng.controller;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.feicheng.base.common.DaoConstant;
import com.feicheng.base.exception.SystemException;
import com.feicheng.base.result.Result;
import com.feicheng.entity.SaleOrderHeader;
import com.feicheng.entity.SaleOrderItem;
import com.feicheng.service.ISaleOrderHeaderService;
import com.feicheng.service.ISaleOrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hao.zhang
 * @since 2022-07-04
 */
@RestController
@RequestMapping("/sale-order-item")
public class SaleOrderItemController {

    /**
     * 销售详情页面
     * @param saleId (销售表主键)
     * @author shuoyu.qian
     * @return
     */
    @Autowired
    ISaleOrderItemService iSaleOrderItemService;

    @PostMapping("/sale_order/info/g")
    public Result saleOrderItemPage(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "4") Integer size,
            @RequestParam Integer saleId){
        //当提成主键没有传的时候
        if (null == saleId) {
            //TODO
            throw new SystemException("主键不能为空！");
        }

        //构造条件查询
        QueryWrapper<SaleOrderItem> queryWrapper = new QueryWrapper<>();

        //把销售订单编号当作条件，放在构造器当作查询
        queryWrapper.eq("sale_id",saleId);

        // 创建分页查询
        Page<SaleOrderItem> pageInfo = new Page<>(current, size);

        //查询数据并返回结果
        return Result.success(iSaleOrderItemService.selectItemPage(pageInfo,queryWrapper));

    }
}